<template>
  <div class="login-container">
    <!-- 顶部导航栏 -->
    <header class="top-navbar">
      <div class="navbar-content">
        <span class="university-name">四川大学锦江学院</span>
        <span class="auth-status">正在进行身份验证</span>
      </div>
    </header>

    <!-- 主体内容 -->
    <main class="login-content">
      <!-- 左侧图片区域 (60%) -->
      <div class="login-banner">
        <div class="banner-overlay">
          <h2 class="banner-title">四川大学锦江学院研究生监考报名系统</h2>
          <p class="banner-subtitle">严谨 · 高效 · 公平 · 公正</p>
        </div>
      </div>

      <!-- 右侧登录区域 (40%) -->
      <div class="login-form-container">
        <div class="login-form">
          <h2 class="form-title">账号登录</h2>

          <!-- 用户名输入 -->
          <div class="input-group">
            <label for="username">用户名</label>
            <input
                id="username"
                type="text"
                v-model="loginForm.username"
                placeholder="请输入学号/工号"
            >
          </div>

          <!-- 密码输入 -->
          <div class="input-group">
            <label for="password">密码</label>
            <input
                id="password"
                type="password"
                v-model="loginForm.password"
                placeholder="请输入密码"
                @keyup.enter="handleLogin"
            >
          </div>

          <!-- 身份角色选择 -->
          <div class="input-group">
            <label for="role">身份角色</label>
            <select
                id="role"
                v-model="loginForm.role"
                class="role-select"
            >
              <option value="" disabled selected>请选择您的身份</option>
              <option value="staff">在职在岗教职工</option>
              <option value="director">研公办主任</option>
              <option value="officer">研究生招生考务科长</option>
              <option value="student">学生</option>
            </select>
          </div>

          <!-- 记住密码选项 -->
          <div class="remember-group">
            <label class="remember-label">
              <input type="checkbox" v-model="rememberMe">
              <span>记住账号密码</span>
            </label>
          </div>

          <!-- 登录按钮 -->
          <button class="login-btn" @click="handleLogin">登 录</button>

          <!-- 其他登录方式 -->
          <div class="other-login">
            <div class="divider"></div>
            <span class="divider-text">其他登录方式</span>
            <div class="divider"></div>
          </div>

          <!-- 扫码登录 -->
          <div class="qr-login">
            <div class="qr-code">
              <div class="qr-placeholder"></div>
              <span>微信扫码登录</span>
            </div>
          </div>

          <!-- 注册链接 -->
          <div class="register-link">
            没有账号？<router-link to="/register">立即注册</router-link>
          </div>

          <!-- 温馨提示 -->
          <div class="tip-section">
            <div class="tip-icon">!</div>
            <p>温馨提示：用户名为学号或工号；请注意周围环境是否安全保护个人隐私</p>
          </div>
        </div>
      </div>
    </main>

    <!-- 底部信息 -->
    <footer class="bottom-footer">
      <div class="footer-content">
        <span>四川大学锦江学院</span>
        <span>|</span>
        <span>学校官网：<a href="http://www.scdx.com" target="_blank">www.scdx.com</a></span>
        <span>|</span>
        <span>邮箱：<a href="mailto:12456@qq.com">12456@qq.com</a></span>
      </div>
    </footer>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';

interface LoginForm {
  username: string;
  password: string;
  role: string;
}

const router = useRouter();
const loginForm = ref<LoginForm>({
  username: '',
  password: '',
  role: ''
});
const rememberMe = ref<boolean>(false);

const handleLogin = (): void => {
  if (!loginForm.value.username || !loginForm.value.password || !loginForm.value.role) {
    alert('请填写完整登录信息');
    return;
  }

  // 保存用户信息到本地存储
  localStorage.setItem('userInfo', JSON.stringify({
    username: loginForm.value.username,
    role: loginForm.value.role
  }));

  // 根据角色跳转到不同页面 - 修复跳转逻辑
  if (loginForm.value.role === 'director') {
    // 研工办主任跳转到专属仪表盘
    router.push('/dashboard2');
  } else if (['staff', 'officer'].includes(loginForm.value.role)) {
    // 其他教职工跳转到普通仪表盘
    router.push('/dashboard');
  } else {
    // 学生跳转到学生仪表盘
    router.push('/student/dashboard');
  }
};
</script>

<style scoped>
/* 新增角色选择样式 */
.role-select {
  width: 100%;
  height: 46px;
  padding: 0 15px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  font-size: 15px;
  transition: border-color 0.3s;
  background-color: white;
  appearance: none; /* 移除默认样式 */
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 15px center;
  background-size: 16px;
}

.role-select:focus {
  border-color: #409eff;
  outline: none;
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
}

/* 其他原有样式保持不变 */
.login-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f5f7fa;
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

.top-navbar {
  height: 60px;
  background-color: #1a2b4b;
  color: white;
  display: flex;
  align-items: center;
  padding: 0 10%;
}

.navbar-content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 500;
}

.auth-status {
  font-weight: normal;
  color: #a8c7ff;
}

.login-content {
  flex: 1;
  display: flex;
}

.login-banner {
  flex: 0 0 60%;
  background: linear-gradient(135deg, #1a3a6c, #2c5282);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.banner-overlay {
  color: white;
  text-align: center;
  padding: 0 15%;
  z-index: 2;
}

.banner-title {
  font-size: 36px;
  font-weight: bold;
  margin-bottom: 20px;
  letter-spacing: 2px;
}

.banner-subtitle {
  font-size: 20px;
  opacity: 0.9;
}

.login-form-container {
  flex: 0 0 40%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background-color: white;
}

.login-form {
  width: 100%;
  max-width: 400px;
}

.form-title {
  text-align: center;
  font-size: 24px;
  color: #1a2b4b;
  margin-bottom: 30px;
  font-weight: 600;
}

.input-group {
  margin-bottom: 20px;
}

.input-group label {
  display: block;
  margin-bottom: 8px;
  color: #555;
  font-size: 14px;
}

.input-group input {
  width: 100%;
  height: 46px;
  padding: 0 15px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  font-size: 15px;
  transition: border-color 0.3s;
}

.input-group input:focus {
  border-color: #409eff;
  outline: none;
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
}

.remember-group {
  margin-bottom: 25px;
  font-size: 14px;
}

.remember-label {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.remember-label input {
  margin-right: 8px;
}

.login-btn {
  width: 100%;
  height: 48px;
  background-color: #1a3a6c;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.3s;
}

.login-btn:hover {
  background-color: #2c5282;
}

.other-login {
  display: flex;
  align-items: center;
  margin: 30px 0;
}

.divider {
  flex: 1;
  height: 1px;
  background-color: #dcdfe6;
}

.divider-text {
  padding: 0 15px;
  color: #999;
  font-size: 14px;
}

.qr-login {
  display: flex;
  justify-content: center;
  margin-bottom: 25px;
}

.qr-code {
  text-align: center;
}

.qr-placeholder {
  width: 120px;
  height: 120px;
  background: linear-gradient(45deg, #f1f5f9, #e2e8f0);
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.qr-placeholder::before,
.qr-placeholder::after {
  content: "";
  position: absolute;
  background-color: #1a3a6c;
  border-radius: 2px;
}

.qr-placeholder::before {
  width: 70px;
  height: 2px;
}

.qr-placeholder::after {
  width: 2px;
  height: 70px;
}

.register-link {
  text-align: center;
  font-size: 14px;
  color: #666;
}

.register-link a {
  color: #1a3a6c;
  text-decoration: none;
  font-weight: 500;
}

.register-link a:hover {
  text-decoration: underline;
}

.tip-section {
  margin-top: 30px;
  padding: 15px;
  background-color: #f0f7ff;
  border-radius: 4px;
  display: flex;
  font-size: 14px;
  color: #1a3a6c;
}

.tip-icon {
  flex: 0 0 24px;
  height: 24px;
  background-color: #1a3a6c;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  font-weight: bold;
}

.bottom-footer {
  height: 50px;
  background-color: #f0f2f5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #666;
}

.footer-content {
  display: flex;
  gap: 15px;
}

.footer-content a {
  color: #1a3a6c;
  text-decoration: none;
}

.footer-content a:hover {
  text-decoration: underline;
}

/* 波浪效果 */
.login-banner::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 20%;
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="%23f5f7fa" fill-opacity="1" d="M0,160L48,149.3C96,139,192,117,288,128C384,139,480,181,576,181.3C672,181,768,139,864,112C960,85,1056,75,1152,90.7C1248,107,1344,149,1392,170.7L1440,192L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>');
  background-size: cover;
  background-position: center bottom;
}

/* 响应式设计 */
@media (max-width: 992px) {
  .login-content {
    flex-direction: column;
  }

  .login-banner {
    flex: 0 0 40%;
    min-height: 300px;
  }

  .login-form-container {
    flex: 1;
    padding: 30px 20px;
  }
}

@media (max-width: 576px) {
  .top-navbar {
    padding: 0 5%;
  }

  .banner-title {
    font-size: 28px !important;
  }

  .banner-subtitle {
    font-size: 16px !important;
  }

  .bottom-footer {
    height: auto;
    padding: 10px 0;
  }

  .footer-content {
    flex-direction: column;
    gap: 5px;
    text-align: center;
  }

  .footer-content span:not(:last-child) {
    display: none;
  }
}
</style>